<template>
  <div class="content">
    <!-- 表格区域 -->
    <el-table height="80.5vh" :data="childApplyList" style="width: 100%" :header-cell-style="{color:'black'}">
      <el-table-column label="企业名称" prop="company_name" min-width="100px" />
      <el-table-column label="联系人" prop="contact" min-width="100px" />
      <el-table-column label="联系方式" prop="telephone" min-width="100px" />
      <el-table-column label="审核状态" prop="status_display" min-width="100px">
        <template v-slot="scope">
          <el-tag
            :type="typeMap[scope.row.status_display]"
            effect="dark"
          >{{ statusMap[scope.row.status_display] }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" prop="created_at" min-width="100px" />
      <el-table-column label="审核人" prop="review[0]" min-width="100px">
        <template v-slot="scope">{{ scope.row.review.length===0?'--' : scope.row.review[0].name }}</template>
      </el-table-column>
      <el-table-column label="审核时间" prop="review[0]" min-width="100px">
        <template
          v-slot="scope"
        >{{ scope.row.review.length===0?'--' : scope.row.review[0].updated_at }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button type="text" @click="viewDetails(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <div class="dingwei">
      <el-pagination
        :current-page="query.page"
        :page-sizes="$arrays.tableSize"
        :page-size="query.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <!-- 弹出对话框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span style="color: black;">{{ row.review[0].content }}</span>
      <span
        style="margin-top: 20px;display: block;color: black;"
      >{{ row.review[0].updated_at }}--{{ row.review[0].name }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getChildApplyList } from '@/api/merchant'
export default {
  name: 'MerchantApply',
  data() {
    return {
      childApplyList: [],
      query: {
        company_name: '',
        telephone: '',
        page: 1,
        limit: 20
      },
      total: 0,
      statusMap: {
        WAIT_REVIEW: '待审核',
        SUCCESS_REVIEW: '已审核',
        REJECT_REVIEW: '已拒绝',
        SUCCESS_PASS: '已发号'
      },
      typeMap: {
        WAIT_REVIEW: 'warning',
        SUCCESS_PASS: '',
        REJECT_REVIEW: 'danger',
        SUCCESS_REVIEW: 'success'
      },
      dialogVisible: false,
      row: {
        review: [{}]
      }
    }
  },
  created() {
    this.getChildApplyList()
  },
  methods: {
    getChildApplyList() {
      getChildApplyList(this.query).then((res) => {
        console.log(res.data.data.data)
        this.total = res.data.data.total
        this.childApplyList = res.data.data.data
      })
    },
    handleSizeChange(newPageSize) {
      this.query.limit = newPageSize
      this.getChildApplyList()
    },
    handleCurrentChange(newPage) {
      this.query.page = newPage
      this.getChildApplyList()
    },
    viewDetails(row) {
      switch (row.status_display) {
        case 'WAIT_REVIEW':
          this.$message({
            showClose: true,
            duration: 1500,
            message: '您的二级商户入驻申请正在审核中。'
          })
          break
        case 'SUCCESS_PASS':
          this.$message({
            showClose: true,
            duration: 1500,
            message: '您的二级商户入驻申请已经通过，注意手机短信。',
            type: 'success'
          })
          break
        case 'SUCCESS_REVIEW':
          this.$message({
            showClose: true,
            duration: 1500,
            message: '您的二级商户入驻申请已经通过，注意手机短信。',
            type: 'success'
          })
          break
        case 'REJECT_REVIEW':
          this.row = row
          this.dialogVisible = true
          break
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  padding: 24px;

  .el-form-item {
    .el-input {
      width: 70%;
    }
  }
  .dingwei {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: white;
    padding-bottom: 50px;
    padding-top: 40px;
  }
}
</style>
